PLC BLOG | Codesys Counter instruction
Share on Facebook Share On Twitter Share on LinkedIn Share on Whatsapp


lg-12 col-12 fb-share-button">

Share on Facebook

Share on twitter

Share on Whats-App

codesys counter instruction

Counter are used for counting bit and increment and decrement of bits, generally two type of counter are used either UP counter or down counter. UP counter counting bits by adding 1 to its current value. for down dounter subtract 1 to its current value.


CTU - counter UP

up counter function block uses as Incrementer. each rising edge at the input (CU) of counter block, increment or add 1 to current value of counter. by default current value is set to 0. input and output of description of block:

codesys CTU - counter UP instruction

data type for input variables input_ctu(CU) and (reset_CU) RESET and output variable out_ctu(Q) are data type BOOL, the input variable PV and the output variable ctu_cv (CV) are type WORD.


CTD counter down

CTD counter down, a Function Block Decrement of loaded Current value by one at each rising edge of CD. by default CV = 0 if load input is set to true then PV value transfer to CV.The input variables CD and LOAD as well as the output variable Q are BOOL data type, the input variable PV and the output variable CV are WORD data type.

codesys CTD counter down instruction

input variables input_cd(CU) and load_cd (LOAD), PV =4, and the output variable ctd_cv (CV) and out_ctds (Q). input variable


CTUD Incrementer/Decrementer counter

CTUD perform increment as well as decrement counter. working and input is same for above counter. Rising edge at input CU, counter work as increment .Rising edge at CD counter work as Decrement.

codesys CTUD Incrementer or Decrementer counter instruction

The input variables CU, CD, RESET, LOAD as well as the output variables QU and QD are data type BOOL, PV and CV are data type WORD.


counter example

in this counter example the value of counter PV set by Move instruntion, timer generate periodic pulse and these pulse counted by counter when current counter value CV is more than PV so counter up reset and again count from 0.

codesys counter example

in above program counter counter increment depend on timer output, each 2s gives a true bit and counter increment by 1. greater than comparison block compare CV and PV when CV > PV counter reset to 0.